import numpy as np
import matplotlib.pyplot as plt

# 定义 x 的值
x = np.linspace(0.01, 1, 400)  # 避免除以0的情况

# 定义条件数 cond_f(x)
def cond_f(x):
    return x / (np.exp(x) - 1)

# 定义条件数 cond_A(x) 的估计
def cond_A(x):  # 假设机器epsilon为 1e-16
    return np.exp(x) / x 

# 计算 cond_f(x) 和 cond_A(x) 的值
cond_f_values = cond_f(x)
cond_A_values = cond_A(x)

# 绘制图像
plt.figure(figsize=(10, 6))
plt.plot(x, cond_f_values, label=r'$\operatorname{cond}_f(x)$', linestyle='-', color='blue')
plt.plot(x, cond_A_values, label=r'Estimated upperbound of $\operatorname{cond}_A(x)$', linestyle='--', color='red')
plt.ylim(0, 10)  # 设置y轴的范围
plt.xlabel('x')
plt.ylabel('Condition Number')
plt.title('Condition Numbers for f(x) and Algorithm A')
plt.legend()
plt.grid(True)
plt.savefig("09.png")